Fix EmptyDataError when reading empty CSV files#995
Merged
benoit-cty merged 2 commits intomlco2:masterfrom Dec 28, 2025
Merged
Conversation
Contributor
|
If we changed line 90 from to something like then I think we could rely on the existing logic without adding more conditionals? Personally I already find the existing logic hard to follow. |
Contributor
Author
|
good idea, done |
Handle pandas.errors.EmptyDataError that occurs when pd.read_csv() encounters an existing but empty CSV file. This fix catches the error in both 'append' and 'update' modes and treats the empty file as if it doesn't exist, creating a new file with the current data. The fix prevents crashes when emission CSV files exist but are empty, which can happen if a previous write operation was interrupted. Added test cases for both append and update modes with empty files.
b5e390b to
9cc0a54
Compare
benoit-cty
approved these changes
Dec 28, 2025
Contributor
benoit-cty
left a comment
There was a problem hiding this comment.
Thanks a lot and sorry for the delay !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug where
pandas.errors.EmptyDataErroris raised when the FileOutput class attempts to read an existing but empty CSV file. The fix adds error handling in theout()method to catch this exception and treat empty files as if they don't exist, creating a new file with the current emissions data.Related Issue
I have not opened an issue.
Motivation and Context
This bug occurs when CSV emission files exist but are empty, which can happen if:
Without this fix, the application crashes with
pandas.errors.EmptyDataError: No columns to parse from filewhen trying to append or update emissions data, preventing users from tracking their carbon emissions.How Has This Been Tested?
Unit Tests: Added two new test cases in
tests/output_methods/test_file.py:test_file_output_out_append_empty_file_exists(): Verifies append mode handles empty files correctlytest_file_output_out_update_empty_file_exists(): Verifies update mode handles empty files correctlyManual Testing:
Pre-commit Hooks: Ran all linting and formatting checks
Test Suite: Ran the full test suite to ensure no regressions:
Screenshots (if appropriate):
N/A - This is a bug fix with no UI changes
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:Checklist:
Go over all the following points, and put an
xin all the boxes that apply.